package com.zr.util;

import lombok.Data;

/**
 * Created by 天赐 on 2019/12/23.
 */

public class PageVo {
    private Integer pageIndex;//当前页
    private Integer pageSize;//每页大小
    private Integer offset;//索引数

    public Integer getPageIndex() {
        return pageIndex;
    }

    public void setPageIndex(Integer pageIndex) {
        this.pageIndex = pageIndex;
        initParamter();
    }

    public Integer getPageSize() {
        return pageSize;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    public Integer getOffset() {
        return offset;
    }

    public void setOffset(Integer offset) {
        this.offset = offset;
    }

    private void initParamter(){
        if (pageIndex==null){//默认第一页
            pageIndex=1;
        }
        if (pageIndex<1){
            pageIndex=1;
        }
        if (this.pageSize==null){
            this.pageSize=10;
        }
        if (this.pageSize==0){
            this.pageSize=10;//默认每页多少条数据
        }
        final int startIndex = (this.pageIndex-1)*this.pageSize;
        setOffset(startIndex);
    }

}
